package app.pumpkin.com.myandroiddemo.service;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;

/**
 * 作者：wangshy
 * 时间： 2018/7/13 12:29
 *
 * @author wangshy
 */
@SuppressLint("Registered")
public class MyService extends Service {
    public MyService() {
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e("onDestroy", "---->>>> (MyService.java:26)" + "服务已经关闭");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e("onStartCommand", "---->>>> (MyService.java:31)" + "启动服务");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.e("onCreate", "---->>>> (MyService.java:38)" + "创建服务");
    }

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        Log.e("onStart", "---->>>> (MyService.java:44)" + "过时启动");
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.e("onUnbind", "---->>>> (MyService.java:49)" + "解绑服务");
        return super.onUnbind(intent);
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.e("onBind", "---->>>> (MyService.java:56)" + "绑定服务");
        return new MyBinder();
    }

    private void methodInMyService() {
        Toast.makeText(getApplicationContext(), "服务里的方法执行了。。。",
                Toast.LENGTH_SHORT).show();
    }

    private class MyBinder extends Binder implements IMyBinder {

        @Override
        public void invokeMethodInMyService() {
            methodInMyService();
        }
    }
}
